package example.collections;

import java.util.Enumeration;
import java.util.Hashtable;

/**
 * Created by lenovo on 2016/11/7 0007.
 * 用 Enumeration 类的 hasMoreElements 和 nextElement 方法来遍历输出 HashTable 中的内容
 */
public class HashTableDemo {
    public static void main(String[] args) {
        Hashtable<String, String> ht = new Hashtable<>();
        ht.put("1", "One");
        ht.put("2", "Two");
        ht.put("3", "Three");
        Enumeration<String> e = ht.elements();
        while (e.hasMoreElements()) {
            System.out.println(e.nextElement());
        }
        Enumeration keys = ht.keys();
        while (keys.hasMoreElements()) {
            System.out.println(keys.nextElement());
        }
    }
}
